package com.hns.phone.master.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysRoleEntity;
import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.web.BaseController;
import com.hns.phone.master.service.PhoneHomeTransitService;
import com.hns.tool.pub.DateTool;

/**
 * 手机app总体概况接口
 * @author:zhangyu
 * @email:zhangyu2222z@sina.cn
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/api/phoneHomeTransit")
public class PhoneHomeTransitController extends BaseController {
	
	@Autowired
	private PhoneHomeTransitService phoneHomeTransitService;//公交首页service
	
	/**
	 * TODO
	 * 	考虑到手机app接受的数据格式和首页不同,
	 * 	暂时每个功能单独作为一个接口方法,
	 * 	以备未来修改数据格式,
	 * 	待手机app各接口数据确定再抽象重构
	 */
	
	/**
	 * 蛛网图数据
	 * @param dateType 日期类型
	 * @param lineId	线路id
	 * @param idxType	业务类型
	 * @return
	 * @throws Exception
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
	@RequestMapping({"/getOverviewChart"})
	@ResponseBody
	public Object getOverviewChart(String dateType, String lineId, String idxType) throws Exception {
		Map<String, Object> map = formatParams(dateType, lineId, idxType);
		List<T> list = phoneHomeTransitService.getHomeData(map, "getOverviewChart", "OverviewChartVo");
		return this.getReturnResult(list);
	}
	
	/**
	 * 基本信息
	 * @param dateType 日期类型
	 * @param lineId	线路id
	 * @param idxType	业务类型
	 * @return
	 * @throws Exception
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
	@RequestMapping({"/initTotallyStatus"})
	@ResponseBody
	public Object initTotallyStatus(String dateType, String lineId, String idxType) throws Exception {
		Map<String, Object> map = formatParams(dateType, lineId, idxType);
		List<T> list = phoneHomeTransitService.getHomeData(map, "initTotallyStatus", "TotallyStatusVo");
		return this.getReturnResult(list);
	}
	
	/**
	 * 代办事项
	 * @param dateType 日期类型
	 * @param lineId	线路id
	 * @param idxType	业务类型
	 * @return
	 * @throws Exception
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
	@RequestMapping({"/loadSchedule"})
	@ResponseBody
	public Object loadSchedule(String dateType, String lineId, String idxType) throws Exception {
		Map<String, Object> map = formatParams(dateType, lineId, idxType);
		List<T> list = phoneHomeTransitService.getHomeData(map, "loadSchedule", "ScheduleVo");
		return this.getReturnResult(list);
	}
	
	
	/**
	 * 初始化参数
	 * @param dateType 日期类型
	 * @param lineId 线路id
	 * @param idxType 业务类型
	 * @return
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
	private Map<String, Object> formatParams(String dateType, String lineId, String idxType){
		SysUserEntity user = this.getPhoneCurrentUser();
		Map<String, Object> map = new HashMap<String, Object>();
		ArrayList<SysRoleEntity> roleList = (ArrayList<SysRoleEntity>) request.getSession().getAttribute("CURRENTUSERROLELIST");
		map.put("dateType", dateType);
		map.put("lineId", lineId);
		map.put("idxType", idxType);
		map.put("corpId", user.getCorpId());
		map.put("userId", user.getId());
		map.put("roleIdList", roleList);
		String dateStr = DateTool.SHORT_DATE_FORMAT.format(new Date());
		map.put("curDate", dateStr);
		return map;
	}
}
